package com.edu.service.impl;

import java.util.List;

import com.edu.dao.BookTypeDao;
import com.edu.dao.impl.BookTypeDaoImpl;
import com.edu.entiy.BookType;
import com.edu.entiy.History;
import com.edu.entiy.Page;
import com.edu.service.BookTypeService;
import com.edu.utils.PageTool;

public class BookTypeServiceImpl implements BookTypeService {
	private BookTypeDao bookTypeDao = new BookTypeDaoImpl();

	@Override
	public Page<BookType> selectByPage(int currentPage, int pageSize) {
		// TODO Auto-generated method stub
		Page<BookType> page = new Page<>();
		int count = bookTypeDao.selectBookTypeDaoCount();
		page.setPageCount(count);
		int begin = (currentPage-1)*pageSize;
		List<BookType> bookTypes = bookTypeDao.selectPageBrand(begin, pageSize);
		page.setPageData(bookTypes);
		return page;
	}

	@Override
	public List<BookType> bookTypes(String tid, String typeName) {
		// TODO Auto-generated method stub
		return bookTypeDao.list(tid, typeName);
	}

	@Override
	public BookType selecBookTypeByTypeName(String typeName) {
		// TODO Auto-generated method stub
		return bookTypeDao.selectByBookType(typeName);
	}

	@Override
	public int addBookType(String typeName) {
		// TODO Auto-generated method stub
		return bookTypeDao.addBookType(typeName);
	}

	@Override
	public int updateBookType(BookType bookType) {
		// TODO Auto-generated method stub
		return bookTypeDao.updateBookType(bookType);
	}

	@Override
	public int deleteBookType(int typeId) {
		// TODO Auto-generated method stub
		return bookTypeDao.deleteBookType(typeId);
	}

	@Override
	public PageTool<BookType> selectByPage(String currentPage, String pageSize) {
		// TODO Auto-generated method stub
		//查询总记录数据
		int count = bookTypeDao.selectBookTypeDaoCount();
		//初始化分页工具
		PageTool<BookType> pageTool = new PageTool<BookType>(count,currentPage,pageSize);
		List<BookType> bookTypes =  bookTypeDao.selectPageBrand(pageTool.getStartIndex(),pageTool.getPageSize());
		pageTool.setRows(bookTypes);
		return pageTool;
	}

	@Override
	public List<BookType> selectBookTypes() {
		// TODO Auto-generated method stub
		return bookTypeDao.list();
	}

	
	

}
